package sketch.specs;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.Statement;

import sketch.ast.ASTUtils;
import sketch.main.SketchTestOptions;
import sketch.specs.annotation.ChooseOne;
import sketch.util.Checker;

public class SketchedChooseOneBlock extends SketchedBlock {
	
	public static final String COMMENT_REPRESENTATION = ChooseOne.value(); //"@ChooseOne";
	
	public SketchedChooseOneBlock(Block realBlock) {
		super(realBlock);
	}

	@Override
	protected List<Block> replicate() {
		List<Block> retBlocks = new LinkedList<Block>();
		List<Statement> statements = this.realBlock.statements();
		for(int i = 0; i < statements.size(); i++) {
			Block replicated_block = ASTUtils.deepClone(this.realBlock);
			Statement statment = ASTUtils.deepClone(statements.get(i)); //this must be deep cloned!
			replicated_block.statements().clear();
			replicated_block.statements().add(statment);
			//add to the return block list
			retBlocks.add(replicated_block);
			//print out the replicated block
			if(SketchTestOptions.verbose) {
			  System.out.println(replicated_block);
			}
		}
		Checker.checkTrue(retBlocks.size() == statements.size(), "The number of ret blocks does not" +
				" equal to the statement num.");
		return retBlocks;
	}

	@Override
	protected SketchedBlock newInstance(Block block) {
		return new SketchedChooseOneBlock(block);
	}

}
